# 这些import进来的模块是同目录下的py文件
import wav2text	# wav2text.py负责wav转文字
import robot	# robot.py负责获得图灵机器人的文字回答
import tts
import os
import return_messages
import local_process as lp
import network_available
import config.config as conf

def start_ai(audio):
    config_info = conf.read_conf()
    if (network_available.is_connected()):
        recognize_result = wav2text.get_text(audio.get_wav_data())
    else:
        recognize_result = wav2text.get_text_offline(audio)
    if (lp.process(recognize_result)):
        turing_answer = robot.chat(recognize_result)	# 得到图灵的回答，返回值是字典格式
        tts.getVoice(config_info["BAIDU_APP_ID"], config_info["BAIDU_APP_KEY"], config_info["BAIDU_SECRET_KEY"], 5, 4, 8, 4, turing_answer['text'], "/home/pi/modules.ai/tmp.wave/answer.mp3")
        return_messages.return_mes(turing_answer['text'])
        os.system("mplayer"+" "+config_info["TEMP_AUDIO_SAVE_PATH"]+"/answer.mp3")
        os.system("rm"+" "+"-rf"+" "+config_info["TEMP_AUDIO_SAVE_PATH"]+"/*")

if __name__ == '__main__':
    start_ai()
